package com.xc.hotelmgr.order.modules.ctrip.controller;

import com.alibaba.fastjson.JSONObject;
import com.xc.hotelmgr.order.common.utils.Constant;
import com.xc.hotelmgr.order.common.utils.HttpClient;
import com.xc.hotelmgr.order.common.utils.R;
import com.xc.hotelmgr.order.common.utils.RedisUtils;
import com.xc.hotelmgr.order.init.Init;
import com.xc.hotelmgr.order.modules.order.entity.DtOrderChannelsEntity;
import com.xc.hotelmgr.order.modules.order.service.DtOrderChannelsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("ctrip/order")
public class RefreshChannel {
    @Autowired
    private DtOrderChannelsService dtOrderChannelsService;

    @Autowired
    private DiscoveryClient discoveryClient;
    @Autowired
    private RedisUtils redisUtils;

    /**
     * 前端调用更新每个order微服务的携程渠道信息
     */
    @GetMapping("refesh/channel")
    public R refeshChannel(){
        List<DtOrderChannelsEntity> ctrips = dtOrderChannelsService.sqlSelectByChanel(Constant.Channel.Ctrip);
        String ctripOrderChannels = JSONObject.toJSONString(ctrips);
        redisUtils.set("ctripOrderChannels",ctripOrderChannels);
        return R.ok();
    }
}
